# callback_cow.py ~ demonstrate ease of adding callbacks to nodes with pyscene
import pyscene, osg
scene = pyscene.pyscene()

# Set a black background:
scene.viewer.getCamera().setClearColor( osg.Vec4f(0, 0, 0, 0) )

# cow.osg should be located in the current or $OSG_FILE_PATH directory
cow = scene.readNodeFile("cow.osg")
if not cow : raise "File not found: cow.osg"
cow.inside = False # whether or not the viewer is inside the cow

def enter_callback (self, nv, node) :
    p = scene.getPosition()
    # osgswig is still somewhat particular about 3f/3d in places:
    p = osg.Vec3f(p[0], p[1], p[2])
    # check to see if the viewer is inside the cow's bounding sphere
    contains = self.getBound().contains(p)
    
    if self.inside != contains :
        # the inside state has changed
        self.inside = contains
        
        # tip: try setting $OSG_WINDOW to "0 0 800 600" or some such to see
        # these printed statements in the console as the app runs in a
        # non-fullscreen window
        if contains == False :
            print "outside"
        else :
            print "inside"
            # do something fun here: piping text to festival, how about
cow.addUpdateCallback(enter_callback)

scene.addChild(cow)
scene.run()

